<?php
class cLog extends CI_Controller{

	function __construct(){
		parent::__construct();
	}

	function viewSignup(){
		global $LANG;
		$this->lang->load('form', $this->config->item('language'));
		//chargement traduction navBarre
		$this->data['trad']['accueil'] = $LANG->language['accueil'];
		$this->data['trad']['video'] = $LANG->language['video'];
		$this->data['trad']['gallerie'] = $LANG->language['gallerie'];
		$this->data['trad']['news'] = $LANG->language['news'];
		$this->data['trad']['projet'] = $LANG->language['projet'];
		$this->data['trad']['cv'] = $LANG->language['cv'];
		$this->data['trad']['pro'] = $LANG->language['pro'];
		$this->data['trad']['jeux'] = $LANG->language['jeux'];
		$this->data['trad']['test'] = $LANG->language['test'];

		//traduction vSignup
		$this->data['trad']['prenom'] = $LANG->language['prenom'];
		$this->data['trad']['nom'] = $LANG->language['nom'];
		$this->data['trad']['anniversaire'] = $LANG->language['anniversaire'];
		$this->data['trad']['confPass'] = $LANG->language['confPass'];

		$this->data['titre'] = 'Inscription';
		$this->load->view('vSignup.tpl', $this->data);
	}

	function signup(){
		global $LANG;
		$this->lang->load('form', $this->config->item('language'));
		//chargement traduction navBarre
		$this->data['trad']['accueil'] = $LANG->language['accueil'];
		$this->data['trad']['video'] = $LANG->language['video'];
		$this->data['trad']['gallerie'] = $LANG->language['gallerie'];
		$this->data['trad']['news'] = $LANG->language['news'];
		$this->data['trad']['projet'] = $LANG->language['projet'];
		$this->data['trad']['cv'] = $LANG->language['cv'];
		$this->data['trad']['pro'] = $LANG->language['pro'];
		$this->data['trad']['jeux'] = $LANG->language['jeux'];
		$this->data['trad']['test'] = $LANG->language['test'];

		//traduction vSignup
		$this->data['trad']['prenom'] = $LANG->language['prenom'];
		$this->data['trad']['nom'] = $LANG->language['nom'];
		$this->data['trad']['anniversaire'] = $LANG->language['anniversaire'];
		$this->data['trad']['confPass'] = $LANG->language['confPass'];

		//chargement helper et library pour formulaire
		$this->load->helper(array('form', 'url'));
		$this->load->library('form_validation');
		//Règle de validation
		$this->form_validation->set_rules('login', 'Login', 'required|min_lenght[5]|is_unique[k_user.Login]|trim|htmlspecialchars|xss_clean');
		$this->form_validation->set_rules('mail', 'e-mail', 'required|min_lenght[5]|is_unique[k_user.Mail]|valid_email|trim|htmlspecialchars|xss_clean');
		$this->form_validation->set_rules('prenom', 'Prenom', 'required|min_lenght[5]|trim|htmlspecialchars|xss_clean');
		$this->form_validation->set_rules('nom', 'Nom', 'trim|htmlspecialchars|xss_clean');
		$this->form_validation->set_rules('birth', 'Birthday', 'required|trim|htmlspecialchars|xss_clean');
		$this->form_validation->set_rules('pwd', 'Password', 'required|min_lenght[5]|trim|htmlspecialchars|xss_clean[matches[passconf]');
		$this->form_validation->set_rules('passconf', 'Password Confirmation', 'required|min_lenght[5]|trim|htmlspecialchars|xss_clean');
		//Si conditions non remplie
		if($this->form_validation->run() == FALSE){
			//chargement de la vue
			$this->load->view('vSignup.tpl', $this->data);
		}
		else{
			//shrfmema
			$pwd = sha1($this->input->post('pwd').sha1($this->input->post('login')));
			//Tableau de données
			$form_data = array(
				'Login'=>$this->input->post('login'),
				'Mail'=>$this->input->post('mail'),
				'Prenom'=>$this->input->post('prenom'),
				'Nom'=>$this->input->post('nom'),
				'birthday'=>$this->input->post('birth'),
				'Password'=>$pwd,
			);
			//chargement du model
			$this->load->model('mLog');
			//récupération d'un possible retour d'érreur
			$this->data['verif_BDD']=$this->mLog->signup($form_data);
			//chargement de la vue
			$this->load->view('index.tpl', $this->data);
		}
	}
}